<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveSupport::CoreExtensions::Time::Zones::ClassMethods</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveSupport::CoreExtensions::Time::Zones::ClassMethods</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../../files/vendor/rails/activesupport/lib/active_support/core_ext/time/zones_rb.html">
                vendor/rails/activesupport/lib/active_support/core_ext/time/zones.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000506">current</a>&nbsp;&nbsp;
      <a href="#M000505">use_zone</a>&nbsp;&nbsp;
      <a href="#M000503">zone</a>&nbsp;&nbsp;
      <a href="#M000504">zone=</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">zone_default</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000506" class="method-detail">
        <a name="M000506"></a>

        <div class="method-heading">
          <a href="#M000506" class="method-signature">
          <span class="method-name">current</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns <tt>Time.zone.now</tt> when <tt>config.time_zone</tt> is set,
otherwise just returns <tt>Time.now</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000506-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000506-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/time/zones.rb, line 50</span>
50:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">current</span>
51:             <span class="ruby-operator">::</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">zone_default</span> <span class="ruby-value">? </span><span class="ruby-operator">::</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">zone</span>.<span class="ruby-identifier">now</span> <span class="ruby-operator">:</span> <span class="ruby-operator">::</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
52:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000505" class="method-detail">
        <a name="M000505"></a>

        <div class="method-heading">
          <a href="#M000505" class="method-signature">
          <span class="method-name">use_zone</span><span class="method-args">(time_zone) {|| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Allows override of <tt>Time.zone</tt> locally inside supplied block; resets
<tt>Time.zone</tt> to existing value when done.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000505-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000505-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/time/zones.rb, line 42</span>
42:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">use_zone</span>(<span class="ruby-identifier">time_zone</span>)
43:             <span class="ruby-identifier">old_zone</span>, <span class="ruby-operator">::</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">zone</span> = <span class="ruby-operator">::</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">zone</span>, <span class="ruby-identifier">get_zone</span>(<span class="ruby-identifier">time_zone</span>)
44:             <span class="ruby-keyword kw">yield</span>
45:           <span class="ruby-keyword kw">ensure</span>
46:             <span class="ruby-operator">::</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">zone</span> = <span class="ruby-identifier">old_zone</span>
47:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000503" class="method-detail">
        <a name="M000503"></a>

        <div class="method-heading">
          <a href="#M000503" class="method-signature">
          <span class="method-name">zone</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the <a href="../../../TimeZone.html">TimeZone</a> for the <a
href="ClassMethods.html#M000506">current</a> request, if this has been set
(via Time.zone=). If <tt>Time.zone</tt> has not been set for the <a
href="ClassMethods.html#M000506">current</a> request, returns the <a
href="../../../TimeZone.html">TimeZone</a> specified in
<tt>config.time_zone</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000503-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000503-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/time/zones.rb, line 14</span>
14:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">zone</span>
15:             <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-identifier">:time_zone</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">zone_default</span>
16:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000504" class="method-detail">
        <a name="M000504"></a>

        <div class="method-heading">
          <a href="#M000504" class="method-signature">
          <span class="method-name">zone=</span><span class="method-args">(time_zone)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets <tt>Time.zone</tt> to a <a href="../../../TimeZone.html">TimeZone</a>
object for the <a href="ClassMethods.html#M000506">current</a>
request/thread.
</p>
<p>
This method accepts any of the following:
</p>
<ul>
<li>A <a href="../../../../Rails.html">Rails</a> <a
href="../../../TimeZone.html">TimeZone</a> object.

</li>
<li>An identifier for a <a href="../../../../Rails.html">Rails</a> <a
href="../../../TimeZone.html">TimeZone</a> object (e.g., &quot;Eastern Time
(US &amp; Canada)&quot;, <tt>-5.hours</tt>).

</li>
<li>A <a href="../../../../TZInfo/Timezone.html">TZInfo::Timezone</a> object.

</li>
<li>An identifier for a <a
href="../../../../TZInfo/Timezone.html">TZInfo::Timezone</a> object (e.g.,
&quot;America/New_York&quot;).

</li>
</ul>
<p>
Here&#8216;s an example of how you might set <tt>Time.zone</tt> on a per
request basis &#8212; <tt>current_user.time_zone</tt> just needs to return
a string identifying the user&#8216;s preferred <a
href="../../../TimeZone.html">TimeZone</a>:
</p>
<pre>
  class ApplicationController &lt; ActionController::Base
    before_filter :set_time_zone

    def set_time_zone
      Time.zone = current_user.time_zone
    end
  end
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000504-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000504-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/time/zones.rb, line 37</span>
37:           <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">zone=</span>(<span class="ruby-identifier">time_zone</span>)
38:             <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-identifier">:time_zone</span>] = <span class="ruby-identifier">get_zone</span>(<span class="ruby-identifier">time_zone</span>)
39:           <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>